package com.chixing.day09.String;

/**
 * "a" + "b" 等价于 new String("a + b")
 * a.concat(b) 等价于 new String("a + b")
 */
public class StringDemoo {
    public static void main(String[] args) {
        //1
        String s1 = "hello";
        s1 = "good";
        System.out.println(s1);

        String s2 = new String("code"); //堆
        String s3 = "code"; //字符串常量池
        System.out.println("s2 == s3 ?: " + (s2 == s3));

        String s4 = "file";
        String s5 = "file";
        System.out.println("s4 == s5 ?: " + (s4 == s5));

        String s6 = new String("help");
        String s7 = new String("help");
        System.out.println("s6 == s7 ?: " + (s6 == s7));


        //2

        String str1 = "hello";
        String str2 = "world";
        String str3 = str1 + str2; //  new String()
        String str4 = "helloworld";
        System.out.println("str3 == str4 ?: " + (str3 == str4));

        String str0 = "hello" + "world"; //拼接之后,放到常量池中
        System.out.println("str0 == str4 ?: " + (str0 == str4));

        String str5 = str1.concat(str2); // new String()
        System.out.println("str3 == str5 ?: " + (str3 == str5));
    }
}
